﻿var plusone =
{
	display: function ()
	{
		var URLs = GadgetPrefs.getArray("UrlList");

		if (URLs && URLs.length > 0)
		{
			var content = "";

			if (GadgetPrefs.getBool("DisplayAsTable"))
			{
				content += "<table id=\"items\" cellpadding=\"0\" cellspacing=\"5\">";

				for (var i = 0; i < URLs.length; i++)
				{
					var url = URLs[i];
					content += "<tr>";
					content += "<td class=\"plusone\"><div class=\"g-plusone\" data-size=\"medium\" data-href=\"" + url + "\"></div></td>";
					content += "<td class=\"url\"><a href=\"" + url + "\" target=\"_blank\">" + url + "</a></td>";
					content += "</tr>\n";
				}

				content += "</table>";
			}
			else
			{
				for (var i = 0; i < URLs.length; i++)
				{
					var url = URLs[i];
					content += "<div class=\"item\" title=\"" + url + "\"><div class=\"g-plusone\" data-size=\"tall\" data-href=\"" + url + "\"></div></div>\n";
				}
			}

			document.getElementById("container").innerHTML = content;
		}

		gadgets.window.adjustHeight();

		window.setTimeout(plusone.addScript, 500);
	},

	addScript: function ()
	{
		var script = document.createElement("script");
		script.type = "text/javascript";
		script.async = true;
		script.src = (document.location.protocol == "https:" ? "https://" : "http://") + "apis.google.com/js/plusone.js";

		var head = document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0];
		if (head)
		{
			head.insertBefore(script, head.firstChild);
		}
	}
};



var analytics =
{
	init: function ()
	{
		_gaq = window._gaq || [];
		_gaq.push(['_setAccount', GadgetPrefs.getString("GoogleAnalyticsCode")]);
		_gaq.push(['_trackPageview']);

		var script = document.createElement("script");
		script.type = "text/javascript";
		script.async = true;
		script.src = (document.location.protocol == "https:" ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";

		var head = document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0];
		if (head)
		{
			head.insertBefore(script, head.firstChild);
		}
	}
};
